package com.junlong0716.enjoylearning

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.afollestad.materialdialogs.MaterialDialog
import com.blankj.utilcode.util.ActivityUtils
import com.junlong0716.enjoylearning.manager.UserManager
import com.junlong0716.enjoylearning.ui.LogInActivity
import com.junlong0716.enjoylearning.ui.ModifyPwdActivity
import kotlinx.android.synthetic.main.activity_setting.*
import kotlinx.android.synthetic.main.view_title_bar.*

class SettingActivity : AppCompatActivity(), View.OnClickListener {
    override fun onClick(v: View?) {
        when (v!!.id) {
            R.id.rl_back -> {
                finish()
            }
            R.id.bt_log_out -> {
                MaterialDialog.Builder(this)
                        .title("是否退出当前账号？")
                        .canceledOnTouchOutside(false)
                        .positiveText("是")
                        .negativeText("否")
                        .onPositive { dialog, which ->
                            UserManager.setLoginState(false)
                            dialog.dismiss()
                            ActivityUtils.finishAllActivities()
                            val intent = Intent(this@SettingActivity, LogInActivity::class.java)
                            startActivity(intent)

                        }
                        .onNegative { dialog, which ->
                            dialog.dismiss()
                        }
                        .show()
            }

            R.id.rl_modify_pwd -> {
                val intent = Intent(this,ModifyPwdActivity::class.java)
                startActivity(intent)
            }


            else -> {
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting)
        tv_title.text = "设置"
        rl_back.setOnClickListener(this)
        bt_log_out.setOnClickListener(this)
        rl_modify_pwd.setOnClickListener(this)
    }
}
